<%@page import="by.epam.communalservices.entity.JkhTeam"%>
<%@page import="by.epam.communalservices.dao.jdbc.JdbcDaoJkhTeam"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib tagdir="/WEB-INF/tags/connect" prefix="connect"%>
<%@ taglib tagdir="/WEB-INF/tags/worker" prefix="worker"%>
<%@ taglib tagdir="/WEB-INF/tags/table" prefix="table"%>
<%@ taglib tagdir="/WEB-INF/tags/team" prefix="team"%>
<%@ taglib tagdir="/WEB-INF/tags/task" prefix="task"%>
<%@ taglib tagdir="/WEB-INF/tags/user" prefix="user"%>

<connect:isset/>
<connect:denny rules="admin,edit,team_edit,team_view,kadrovik,brigadir,tasker,objecter" />

<connect:rule val="editor" rules="admin,edit,team_edit,kadrovik" />
<connect:rule val="brigadir" rules="admin,edit,team_edit,kadrovik,brigadir" />


<team:edit id="${param.id}" name="${param.name}"
	surname="${param.surname}" patronymic="${param.patronymic}"
	owner="${param.owner}" submit="${param.submit}"
	delete="${param.delete}" />

<c:if test="${form}">
	<team:append id="${requestScope.team.id}" remove="${param.remove}"
		add="${param.add}" append="${param.append}" />
</c:if>


<c:if test="${requestScope.message ne ''}">
	<p class='message'>
		<c:out value="${message}" />
	</p>
</c:if>
<c:if test="${param.delete gt 0}">
	<c:import url="/WEB-INF/pages/team_view.jsp" />
</c:if>

<c:if test="${form}">
	<c:if test="${work}">
		<form method='POST' action='team_edit' style="float:right;position:relative;display:inline;">
			<table:body style='width:300px;'>
				<table:title span="4">
      				Состав бригады
				</table:title>

				<tr id=c>
					<td colspan=4 id=l>
					<input name='id' value="${requestScope.team.id}" type="hidden">
					<team:team id="${requestScope.team.id}" edit="${editor or (sessionScope.currentUser.id eq requestScope.team.idOwner)}" link="${true}"/>
					</td>
				</tr>

				<table:title span="4" down="yes">
					<c:if test="${editor or (sessionScope.currentUser.id eq requestScope.team.idOwner)}">
						<worker:free name="add" />
						<input name='append' value='save' type='submit' />
					</c:if>
				</table:title>
			</table:body>
		</form>
	</c:if>


	<form name='team' method='POST' action='team_edit' style="clear:left;position:relative;">
		<table:body style='width:50%;'>
			<table:title span="4">
				<c:choose>
					<c:when test="${param.id gt 0}">
      				Редактирование бригады
  				</c:when>
					<c:otherwise>
      				Добавление бригады
  				</c:otherwise>
				</c:choose>
			</table:title>

			<input name='id' value="${requestScope.team.id}" type="hidden">

			<tr id=c>
				<td colspan=2 class=t>Фамилия</td>
				<td colspan=2 class=t id=l>
					<c:choose>
					<c:when test="${editor}">
						<input name='surname' value="${requestScope.team.surname}" />
  					</c:when>
					<c:otherwise>
						<c:out value="${requestScope.team.surname}" />
					</c:otherwise>
					</c:choose>
				</td>
			</tr>

			<tr id=c>
				<td colspan=2 class=t>Имя</td>
				<td colspan=2 class=t id=l>
					<c:choose>
					<c:when test="${editor}">
						<input name='name' value="${requestScope.team.name}" />
  					</c:when>
					<c:otherwise>
						<c:out value="${requestScope.team.name}" />
					</c:otherwise>
					</c:choose>
				</td>
			</tr>

			<tr id=c>
				<td colspan=2 class=t>Отчество</td>
				<td colspan=2 class=t id=l>
					<c:choose>
					<c:when test="${editor}">
						<input name='patronymic' value="${requestScope.team.patronymic}" />
  					</c:when>
					<c:otherwise>
						<c:out value="${requestScope.team.patronymic}" />
					</c:otherwise>
					</c:choose>
				</td>
			</tr>

			<tr id=c>
				<td colspan=2 class=t>Привязка</td>
				<td colspan=2 class=t id=l>
					<c:choose>
					<c:when test="${editor}">
						<user:select name="owner" attr="style='width:140px;'"
						selected="${requestScope.team.idOwner}" roleMarker="brigadir" />
  					</c:when>
					<c:otherwise>
						<user:name id="${requestScope.team.idOwner}" />
					</c:otherwise>
					</c:choose>
				
				
				</td>
			</tr>

			<table:title span="4" down="yes">
				<c:if test="${editor}">
					<input name='submit' value='save' type='submit'>
				</c:if>
			</table:title>
		</table:body>
	</form>


	<c:if test="${work}">
		<br/><br/>
		<team:task id="${requestScope.team.id}" />
		<table:body>
			<table:title span="8">
		   		Task List!!!
			</table:title>
			<table:head names="id,idObject,idTeam,jobDescription,performTime,status,request,action" />
			<c:set var="index" value="0" />
			<c:forEach items="${requestScope.taskList}" var="task">
				<c:set var="index" value="${index + 1}" />
				<task:line  task="${task}" dif="${index mod 2 eq 0 ? 'c' : 'n'}" />	
			</c:forEach>

			<table:title span="8" down="yes">
			</table:title>
		</table:body>
	</c:if>

</c:if>
